import 'package:flutter/material.dart';
import 'home.dart';

void main() {
  return runApp(new MaterialApp(
    theme: new ThemeData(primaryColor: Colors.green),
    home: new HaHaMxApp(),
  ));
}

class HaHaMxApp extends StatefulWidget {
  @override
  HaHaMxAppState createState() {
    return new HaHaMxAppState();
  }
}

class HaHaMxAppState extends State<HaHaMxApp> {
  final List<StatefulWidget> _pages = [new HomePage(),new HomePage(),new HomePage(),new HomePage()];
  int _pageIndex = 0;
  List<BottomNavigationBarItem> getBottomNavigationBarItems() {
    List<BottomNavigationBarItem> tabItems = [
      new BottomNavigationBarItem(
          title: new Text(
            "首页",
            style: new TextStyle(color: getTabColor(0)),
          ),
          icon: new Icon(
            Icons.home,
            color: getTabColor(0),
          )),
      new BottomNavigationBarItem(
          title: new Text(
            "发现",
            style: new TextStyle(color: getTabColor(1)),
          ),
          icon: new Icon(
            Icons.room,
            color: getTabColor(1),
          )),
      new BottomNavigationBarItem(
          title: new Text(
            "消息",
            style: new TextStyle(color: getTabColor(2)),
          ),
          icon: new Icon(
            Icons.message,
            color: getTabColor(2),
          )),
      new BottomNavigationBarItem(
          title: new Text(
            "我",
            style: new TextStyle(color: getTabColor(3)),
          ),
          icon: new Icon(
            Icons.person,
            color: getTabColor(3),
          ))
    ];
    return tabItems;
  }

  Color getTabColor(int index) {
    if (index == _pageIndex) {
      return Colors.green;
    } else {
      return Colors.grey;
    }
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text("哈哈MX"),
        //actions: <Widget>[new Icon(Icons.add, color: Colors.white)],
      ),
      body: _pages[_pageIndex],
      bottomNavigationBar: new BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        items: getBottomNavigationBarItems(),
        onTap: (int i) {
          setState(() {
            _pageIndex = i;
          });
        },
      ),
    );
  }
}
